package com.itheima.search.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.search.mapper.CheckItemMapper;
import com.itheima.search.model.entity.PageResult;
import com.itheima.search.model.entity.QueryPageBean;
import com.itheima.search.model.pojo.CheckGroup;
import com.itheima.search.model.pojo.CheckItem;
import com.itheima.search.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Lee
 * @created 2024/5/11
 * @describtion
 */
@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;


    /**
     * 新增检查项
     *
     * @param checkItem
     */
    @Override
    public void save(CheckItem checkItem) {
        checkItemMapper.insert(checkItem);
    }

    /**
     * 删除检查项
     *
     * @param id
     */
    @Override
    public void delItem(Integer id) {
        checkItemMapper.delItem(id);
    }

    /**
     * 检查项分页查询-条件查询
     *
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult page(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<CheckItem> page = checkItemMapper.page(queryPageBean);
        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 根据id查询检查项
     *
     * @param id
     * @return
     */
    @Override
    public CheckItem findById(Integer id) {
        CheckItem checkItem = checkItemMapper.findById(id);
        return checkItem;
    }

    /**
     * 查询所有的检查项
     *
     * @return
     */
    @Override
    public List<CheckItem> findAll() {
        List<CheckItem> checkItems = checkItemMapper.findAll();
        return checkItems;
    }

    /**
     * 修改检查项
     *
     * @param checkItem
     */
    @Override
    public void update(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
    }
}
